define(['app'], function(app) {
	'use strict';

	//实例化方法
	var factory = function(Http) {
		//已同意、已拒绝
		function get_data_friendList(result) {
			if(false) {
				result = '{"success": true,"msg": "","result": {"member": [' +
					'{"member_id": "001","name": "Mary","mobile": "18912345678"},' +
					'{"member_id": "002","name": "Jane","mobile": "18912345678"}]},"session": "7311da98bd0f18eb15a96bcb263f4153"}';
				return JSON.parse(result);
			} else {
				return result;
			}
		}
		//待确认
		function get_data_applyList(result) {
			if(false) {
				result = '{"success": true,"msg": "","result": {"member": [' +
					'{"member_id": "001","name": "Mary","mobile": "18912345678"},' +
					'{"member_id": "002","name": "Jane","mobile": "18912345678"}]},"session": "7311da98bd0f18eb15a96bcb263f4153"}';
				return JSON.parse(result);
			} else {
				return result;
			}
		}
		//黑名单
		function get_data_blackList(result) {
			if(false) {
				result = '{"success": true,"msg": "","result": ' +
					'{"shielding": [' +
					'{"id": "001","name": "世达","resean": "差评太多","contact_name": "张小三","contact_mobile": "18912345678","brand": [' +
					'{"name": "品牌001"},' +
					'{"name": "品牌002"}],"store_cat": [' +
					'{"store_cat_name": "品类001"},' +
					'{"store_cat_name": "品类002"}]}]},' +
					'"session": "7311da98bd0f18eb15a96bcb263f4153"}';
				return JSON.parse(result);
			} else {
				return result;
			}
		}
		//操作
		function operateFriend(result) {
			if(false) {
				result = '{"success": true,"msg": "","result": {"member_id": "001"},"session": "7311da98bd0f18eb15a96bcb263f4153"}';
				return JSON.parse(result);
			} else
				return result;
		}

		
		return {
			//已同意和已拒绝列表
			get_friend_list: function(status,nPage,callback,calldone) {
				Http.post({
					method: 'member.friends.getlist',
					status:status,
					pagelimit: 10,
					nPage: nPage
				}, function(result) {
					if(callback)
						callback(get_data_friendList(result).result);
				}, function(e) {

				}, function() {
					if(calldone)
						calldone();
				})
			},
			//待确认列表
			get_apply_list: function(nPage,callback,calldone) {
				Http.post({
					method: 'member.friends.applylist',
					pagelimit: 10,
					nPage: nPage
				}, function(result) {
					if(callback)
						callback(get_data_applyList(result).result);
				}, function(e) {

				}, function() {
					if(calldone)
						calldone();
				})
			},
			//黑名单列表
			get_black_list: function(nPage,callback,calldone) {
				Http.post({
					method: 'member.shielding.getlist',
					pagelimit: 10,
					nPage: nPage
				}, function(result) {
					if(callback)
						callback(get_data_blackList(result).result);
				}, function(e) {

				}, function() {
					if(calldone)
						calldone();
				})
			},
			//同意
			get_agree: function(member_id, callback) {
				Http.post({
					method: 'member.friends.agree',
					member_id: member_id
				}, function(result) {
					if(callback)
						callback(operateFriend(result));
				}, function(e) {

				}, function() {

				})
			},
			//删除
			get_delete: function(member_id, callback) {
				Http.post({
					method: 'member.friends.delete',
					member_id: member_id
				}, function(result) {
					if(callback)
						callback(operateFriend(result));
				}, function(e) {

				}, function() {

				})
			},
			//拉黑
			defriend:function(member_id,reason,callback){
				Http.post({
					method:'member.shielding.submit',
					member_id:member_id,
					resean:reason//后台写的是resean
				},function(result){
					if(callback)
					callback(operateFriend(result));
				},function(e){
					
				},function(){
					
				})
			},
			//取消黑名单
			cancleDefriend:function(member_id,callback){
				Http.post({
					method:'member.shielding.cancel',
					member_id:member_id
				},function(result){
					if(callback)
						callback(operateFriend(result));
				},function(e){
					
				},function(){
					
				})
			},
			//拒绝
			refuse:function(member_id,reason,callback){
				Http.post({
					method:'member.friends.refuse',
					member_id:member_id,
					reason:reason
				},function(result){
					if(callback)
						callback(operateFriend(result));
				},function(e){
					
				},function(){
					
				})
			}
			

		};
	}

	factory.$inject = ['Http'];
	return app.registerService("Myfriend", factory);
});